<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>信贷一站通</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link href="../favicon.ico" rel="shortcut icon" />

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<style>
			.title {margin: 20px 15px 10px;color: #6d6d72;font-size: 15px;}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" </h1> 
		</header> <!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul class="mui-table-view">
				</ul>
			</div>
		</div>
		<!-- 底部菜单 -->
		<nav class="mui-foot-bar">
		</nav>
	</body>
	<script src="../js/mui.min.js"></script>
	<script src="../js/jquery-3.3.1.min.js"></script>
	<script src="../js/frame-utils.min.js"></script>
	<script src="../js/frame-setting.min.js?v=004"></script>
	<script>
		var pageNo = 1; //页码
		var totalPage = 1; //总页码
		var clearList = true; // 是否清除列表

		(function(mui, window) {
			totalPage = 1;
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			//加载底部菜单
			mui(".mui-foot-bar").load('../layout/foot1.html', function() {
				//首页
				$("#home").attr("href", contextName + "/index.html");
				//常用工具
				$("#tools").attr("href", contextName + "/modules/tools_list.html");
			});

			//页面初始化
			mui.ready(loadList);
		})(mui, window);

		/**
		 * 下拉刷新
		 */
		function pulldownRefresh() {
			setTimeout(function() {
				pageNo = 1;
				clearList = true;
				loadList();

				mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
			}, 1000);
		}
		/**
		 * 上拉加载具体业务实现
		 */
		function pullupRefresh() {
			setTimeout(function() {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh((pageNo >= totalPage)); //参数为true代表没有更多数据了。
				clearList = false;
				loadList();
			}, 1000);
		}

		//加载列表
		function loadList() {
			var nav = getQuery("nav");
			var url = serverUrl;

			if (isEmpty(nav)) {
				mui.alert("加载错误，缺少参数！", '提示', function() {});
			}
			switch (nav) {
				case "kkzq":
					url += kkzqApi;
					break;
				case "dkzq":
					url += dkzqApi;
					break;
				case "tezq":
					url += tezqApi;
					break;
				case "hkzq":
					url += hkzqApi;
					break;
			}
			//console.log(url);
			get(url, "showCount=30&pageNo=" + pageNo, function(rsp) {

				//console.log(rsp)
				if (!rsp.status) {
					mui.alert(rsp.msg, '提示', function() {});
					return;
				}
				document.title = rsp.channel + "_信贷一站通";

				totalPage = rsp.data.pageTotal; //总页码
				console.log("pageNo=" + pageNo + ",size=" + rsp.data.length + ",totalPage=" + totalPage);

				pageNo++;
					
				$(".mui-title").html(rsp.channel);
				if (clearList) {
					$(".mui-table-view").empty();
				}

				mui.each(rsp.data.data, function(index, article) {
					var html = "<li class=\"mui-table-view-cell mui-media\">" +
						"	<a href=\"javascript:;\" url=\"" + article.url + "\" articleId=\"" + article.articleId +
						"\" articleType=\"" + article.articleType + "\">" +
						"		<img class=\"mui-media-object mui-pull-left\" src=\"" + article.articleImg + "\">" +
						"		<div class=\"mui-media-body\">" +
						//"			" + article.title + " " +
						"			<p class='mui-ellipsis'>" + article.title + " </p>" +
						"		</div>" +
						"	</a>" +
						"</li>";
					$(".mui-table-view").append(html);
				});
				//详情
				showDetail();
			});
		}
		//打开文章详情
		function showDetail() {
			mui(".mui-table-view-cell").on('tap', 'a', function() {
				var articleId = this.getAttribute("articleId");
				var articleType = this.getAttribute("articleType");

				var showUrl = contextName + "/modules/news_show.html?key=" + articleId;
				if (articleType == 1) { // 外链
					showUrl = this.getAttribute("url");
				}
				openPage("ArticleShow", showUrl);
			});
		}
	</script>
</html>
